/**
 * Created by skiy on 16-5-23.
 */

$(function () {
    var winHeight = $(document).scrollTop();

    /**
     * 初始化页面
     */
    $(document).ready(function () {
        adjustmentNav(winHeight);
    });

    //上下滚动
    $(window).scroll(function () {
        var scrollTop = $(this).scrollTop();
        var wH = $(window).height();

        //右侧悬浮窗
        showBackTop(wH, scrollTop);

        //导航栏效果
        adjustmentNav(scrollTop);
    });

    //悬浮窗
    $('#public_service .side em').mouseover(function () {

        var idx = $(this).index();
        $('#public_service .side em > span').hide();
        $(this).children('span').show();
    }).mouseleave(function () {
        $('#public_service .side em > span').hide();
    });

    //返回顶部
    $('#public_service .side .top').click(function () {
        $("body").scrollTo(0, 500);
    });

    //在线客服
    $('#public_service .side .online').click(function () {
        var url = "http://wpa.qq.com/msgrd?v=3&uin=3050682890&site=ekong&menu=yes";
        window.open(url);
    });

    /**
     * 调整导航栏
     * @param h
     */
    function adjustmentNav(h) {
        var navBn = $('.home_h_header .navbar-fixed-top');
        if(h > 80) {
            //navBn.css('top', 0);
            $('.home_h_header .head_brand').addClass('index-h-header');
            $('.home_h_header .logo').css('background-image', 'url(/static/v1/images/logo2.png)');
            $('#hamburger').removeClass('header-menu-icon');
            $('#hamburger').addClass('header-menu-icon-other');
        } else {

            $('.home_h_header .head_brand').removeClass('index-h-header');
            $('.home_h_header .logo').css('background-image', 'url(/static/v1/images/logo.png)');
            $('#hamburger').removeClass('header-menu-icon-other');
            $('#hamburger').addClass('header-menu-icon');
            //navBn.css('top', 20);
        }
    }

    /**
     * 返回顶部
     * @param wH
     * @param sT
     */
    function showBackTop(wH, sT) {
        var obj = $('#public_service .side em.top');
        if (sT > wH) {
            obj.fadeIn().css("display","block");
        } else {
            obj.fadeOut().css("display");
        }
    }

    function switchMobileNav(flag) {
        var mn = $(".header-mobile-nav");
        var mask = $(".header_mask");
        if (flag) {
            mn.addClass("show");
            mask.addClass("show");
            return;
        }

        mn.removeClass("show");
        mask.removeClass("show");
    }

    $("#hamburger").click(function () {
        switchMobileNav(true);
    });
    $(".header_mask").click(function () {
        //$("body").css("overflow-x", "hidden"),
        switchMobileNav(false);
    });
});